/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kimstore.utilities;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DateUtil {

    public static final String SQL_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String HUMAN_READABLE_FORMAT = "MMMMM dd, yyyy, h:mm a";
    public static final String TIME = "h:mm a";
    public static final String JXDATE = "EEE MM/dd/yyyy";
    public static final String REPORT_DATE = "yyyy-MM-dd";

    public static String formatDate(Date date, String format) {
        SimpleDateFormat dt = new SimpleDateFormat(format);

        return dt.format(date);
    }

    public static String formatDate(Date date) {
        SimpleDateFormat dt = new SimpleDateFormat(HUMAN_READABLE_FORMAT);

        return dt.format(date);
    }

    public static Date parseDate(String date) {
        SimpleDateFormat dt = new SimpleDateFormat(HUMAN_READABLE_FORMAT);
        try {
            return dt.parse(date);
        } catch (ParseException ex) {
            Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public static Date parseDate(String date, String format) {
        SimpleDateFormat dt = new SimpleDateFormat(format);
        try {
            return dt.parse(date);
        } catch (ParseException ex) {
            Logger.getLogger(DateUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
